<?php

namespace app\mobile\controller;

use app\common\controller\Frontend;
use think\Db;
use think\Request;

class Huiyipeixun extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {
		$banner=Db::name('banner')->where([
			'type_data'=>1,
			'bannertype_id'=>4
		])->find();
		$this->assign('banner',$banner);
		
		$huiyipeixuntype=Db::name('huiyipeixuntype')->where([
			'show_switch'=>1,
		])->order('weigh desc')->select();
		foreach($huiyipeixuntype as $k=>$v){
			$huiyipeixuntype[$k]['list']=Db::name('huiyipeixun')->where(['huiyipeixuntype_id'=>$v['id']])->order('weigh desc')->select();
		}
		$all_huiyipeixun=Db::name('huiyipeixun')->order('weigh desc')->select();
		$this->assign('huiyipeixuntype',$huiyipeixuntype);
		$this->assign('all_huiyipeixun',$all_huiyipeixun); 
        return $this->view->fetch();
    }
	
	public function detail(Request $request){
		$id=$request->param('id/d',0);
		$rs=Db::name('huiyipeixun')->alias('h')->field('h.*,t.name as type_name')
		->join('huiyipeixuntype t','t.id=h.huiyipeixuntype_id','LEFT')->where(['h.id'=>$id])->find();
		if(is_null($rs)){
			$this->error('内容不存在');
		}
		$this->assign('rs',$rs);
		return $this->view->fetch();
	}

}
